package 算法.leetcode.array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author lchenglong
 * @date 2022/3/24
 */
public class DiffArray {

    public static void main(String[] args) {
        int[] a = new int[]{1,2,3,4};
        int[] b = new int[]{1,2,3,4};
        List<Integer> ans = f(a, b);
        System.out.println(Arrays.toString(new List[]{ans}));
        int[] array = ans.stream().mapToInt(Integer::valueOf).toArray();

    }

    public static List<Integer> f(int[] a, int[] b) {
        List<Integer> ans = new ArrayList<Integer>();
        int flag = 0, i = 0, j = 0;
        for (; i < a.length && j < b.length; ) {
            if (flag == 1 &&a[i]!=b[j])break;
            if (a[i] < b[j] ) {
                ans.add(a[i]);
                i++;
            } else if (a[i] == b[j]) {
                i++;
                j++;
                flag = 1;
            } else  {
                ans.add(b[j]);

                j++;
            }
        }
        // 剩余的写入
        for (;j<b.length;j++)ans.add(b[j]);
        for (;i<a.length;i++)ans.add(a[i]);
        return ans;
    }
}
